package com.pingan.agentbank.aaos.testme;

import com.pingan.agentbank.aaos.exception.AAOSException;
import com.pingan.agentbank.aaos.util.LineHandler;
import com.pingan.vframe.util.ClassCreator;
import javassist.CannotCompileException;

public class ClassGenerate {

    public static TestHandler generate(String param){
        ClassCreator ci = new ClassCreator();


        ci.addInterface(TestHandler.class);

        StringBuffer method = new StringBuffer();
        method.append("public int handle(int a,int b) {\n");
        method.append(param);
        method.append("}");



        ci.addMethod(method.toString());



        TestHandler testHandler;

        try {
            Class clazz = ci.makeClass();
            testHandler = (TestHandler) clazz.newInstance();


        } catch (Exception e) {
            throw new AAOSException(e.getMessage());
        }
        return testHandler;
    }

    public static TestHandler generate(String param,String name){
        ClassCreator ci = new ClassCreator();


        ci.setClassName(name);
        ci.addInterface(TestHandler.class);

        StringBuffer method = new StringBuffer();
        method.append("public int handle(int a,int b) {\n");
        method.append(param);
        method.append("}");



        ci.addMethod(method.toString());



        TestHandler testHandler;

        try {
            Class clazz = ci.makeClass();
            testHandler = (TestHandler) clazz.newInstance();


        } catch (Exception e) {
            throw new AAOSException(e.getMessage());
        }
        return testHandler;
    }
}
